package com.zenithmind.chat.pojo.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Max;

/**
 * 群组设置DTO - 遵循单一职责原则
 * 只负责群组设置的数据传输
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@Schema(description = "群组设置DTO")
public class ChatGroupSettingDTO {

    @Schema(description = "群组ID")
    @NotBlank(message = "群组ID不能为空")
    private String groupId;

    @Schema(description = "群组名称")
    @Size(max = 50, message = "群组名称长度不能超过50个字符")
    private String groupName;

    @Schema(description = "群组描述")
    @Size(max = 500, message = "群组描述长度不能超过500个字符")
    private String description;

    @Schema(description = "群组头像")
    private String avatar;

    @Schema(description = "群组公告")
    @Size(max = 1000, message = "群组公告长度不能超过1000个字符")
    private String notice;

    @Schema(description = "加群验证")
    private Boolean joinVerification;

    @Schema(description = "全员禁言")
    private Boolean allMuted;

    @Schema(description = "是否公开群组")
    private Boolean isPublic;

    @Schema(description = "允许成员邀请")
    private Boolean allowMemberInvite;

    @Schema(description = "最大成员数")
    @Min(value = 2, message = "最大成员数不能少于2人")
    @Max(value = 500, message = "最大成员数不能超过500人")
    private Integer maxMembers;

    @Schema(description = "消息保留天数")
    @Min(value = 1, message = "消息保留天数不能少于1天")
    @Max(value = 365, message = "消息保留天数不能超过365天")
    private Integer messageRetentionDays;

    @Schema(description = "群组标签")
    private String tags;

    @Schema(description = "群组分类")
    private String category;

    @Schema(description = "地理位置")
    private String location;

    @Schema(description = "扩展设置")
    private String extraSettings;

    /**
     * 验证DTO数据
     * 
     * @return 验证结果
     */
    public boolean isValid() {
        return groupId != null && !groupId.trim().isEmpty();
    }

    /**
     * 检查是否需要加群验证
     * 
     * @return 是否需要验证
     */
    public boolean needJoinVerification() {
        return joinVerification != null && joinVerification;
    }

    /**
     * 检查是否全员禁言
     * 
     * @return 是否全员禁言
     */
    public boolean isAllMuted() {
        return allMuted != null && allMuted;
    }

    /**
     * 检查是否为公开群组
     * 
     * @return 是否公开
     */
    public boolean isPublicGroup() {
        return isPublic != null && isPublic;
    }

    /**
     * 检查是否允许成员邀请
     * 
     * @return 是否允许成员邀请
     */
    public boolean allowMemberInvite() {
        return allowMemberInvite != null && allowMemberInvite;
    }

    /**
     * 获取最大成员数，如果未设置则返回默认值
     * 
     * @return 最大成员数
     */
    public Integer getMaxMembersOrDefault() {
        return maxMembers != null ? maxMembers : 100;
    }

    /**
     * 获取消息保留天数，如果未设置则返回默认值
     * 
     * @return 消息保留天数
     */
    public Integer getMessageRetentionDaysOrDefault() {
        return messageRetentionDays != null ? messageRetentionDays : 30;
    }

    /**
     * 检查是否有群组名称更新
     * 
     * @return 是否有名称更新
     */
    public boolean hasGroupNameUpdate() {
        return groupName != null && !groupName.trim().isEmpty();
    }

    /**
     * 检查是否有描述更新
     * 
     * @return 是否有描述更新
     */
    public boolean hasDescriptionUpdate() {
        return description != null;
    }

    /**
     * 检查是否有头像更新
     * 
     * @return 是否有头像更新
     */
    public boolean hasAvatarUpdate() {
        return avatar != null && !avatar.trim().isEmpty();
    }

    /**
     * 检查是否有公告更新
     * 
     * @return 是否有公告更新
     */
    public boolean hasNoticeUpdate() {
        return notice != null;
    }

    /**
     * 检查是否有权限设置更新
     * 
     * @return 是否有权限设置更新
     */
    public boolean hasPermissionUpdate() {
        return joinVerification != null || allMuted != null || 
               isPublic != null || allowMemberInvite != null;
    }

    /**
     * 检查是否有限制设置更新
     * 
     * @return 是否有限制设置更新
     */
    public boolean hasLimitUpdate() {
        return maxMembers != null || messageRetentionDays != null;
    }
}
